<template>
	<view class="container">
		<rf-navbar title="设置" @click="onBack"></rf-navbar>
		<view class="list-item" @click="agreement">
			<view class="text">用户协议</view>
			<view class="right">
				<u-icon name="arrow-right" bold color="#000"></u-icon>
			</view>
		</view>
		<view class="list-item" @click="privacy">
			<view class="text">隐私政策</view>
			<view class="right">
				<u-icon name="arrow-right" bold color="#000"></u-icon>
			</view>
		</view>
		<view class="footer">
			<view class="logout" @click="_logout">
				<text class="text">退出登录</text>
			</view>
		</view>
		<!-- <view class="menu-popup">
			<u-popup :show="show" mode="bottom">
				<view style="margin-top: 10rpx;">
					<view class="cell"><button class="btn" @click="_toLogout">退出</button></view>
					<view class="cell"><button class="btn" @click="cancel">取消</button></view>
				</view>
			</u-popup>
		</view> -->

		<!-- 用户退出登陆提示 -->

		<rf-alert :show="showLogout" @close="showLogout=false" @confirm="onClickLogout" title="退出登录"
			desc="确定退出登录？"></rf-alert>

	</view>
</template>

<script>
	import {
		mapMutations,
		mapState,
	} from 'vuex'; //引入mapState

	import {
		toLogout,
	} from "@/api/login.js"

	export default {
		data() {
			return {
				showLogout: false,
			}
		},
		methods: {
			...mapMutations(['logout']),
			onBack() {
				uni.navigateBack();
			},
			agreement() {
				uni.navigateTo({
					url: "/pages-sub/set/agreement"
				})
			},
			privacy() {
				uni.navigateTo({
					url: "/pages-sub/set/privacy"
				})
			},
			_logout() {
				console.log("-------------------");
				this.showLogout = true
			},
			onClickLogout() {
				// 退出服务器，token失效
				toLogout().then(res => {
					// 设置app登出
					this.logout()
					uni.navigateBack()
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F5F6FA;
	}

	.container {
		.list-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 112rpx;
			background-color: #fff;
			border-bottom: 2rpx solid #f5f6fa;
			margin-top: 20rpx;

			.icon {
				width: 40rpx;
				height: 40rpx;
				margin-left: 42rpx;

			}

			.text {
				flex: 1;
				margin-left: 32rpx;
				font-size: 32rpx;
				font-weight: 500;
				color: #3A3D4B;
				line-height: 44rpx;
			}

			.right {

				padding-right: 30rpx;

			}

		}

		.footer {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;

			display: flex;
			justify-content: center;

			.logout {

				display: flex;
				justify-content: center;
				align-items: center;
				width: 640rpx;
				height: 88rpx;
				background: #58C866;
				border-radius: 44rpx;
				margin-bottom: 108rpx;

				.text {
					width: 128rpx;
					height: 44rpx;
					font-size: 32rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 44rpx;
				}
			}
		}

		.menu-popup {
			width: 100%;

			.cell {
				height: 70rpx;
				margin: 20rpx 60rpx;
				border-radius: 10rpx;

				.btn {
					height: 100%;
					border: 0rpx solid #58c866;
					background-color: #58c866;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 14px;
					color: #fff;
				}
			}
		}

	}
</style>